<?php
require_once '../inc/configuration.php';
require_once '../inc/connexion_bdd.php';
require_once '../inc/session.php';

$id = isset($_GET['id']) ? $_GET['id'] : "";
$where = isset($_GET['id']) ? "WHERE id_entreprise=".$_GET['id'] : "";

$order=isset($_GET['ordre']) ? "ORDER BY nom ".$_GET['ordre']." prenom ".$_GET['ordre'] : "";
$sql="SELECT*FROM contacts".$where.''.$order;
$envoi_requete = mysqli_query($connexion_serveur, $sql);
$nbre_total = mysqli_num_rows($envoi_requete);

?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title>Contacts</title>
        <?php require_once "../inc/css_bootstrap.php" ?>
        <style>
            .table {
                width: 500px;
            }
            
            th {
                width: 35%;
                text-align: right;
            }
        </style>
    </head>
    <body>
          <?php require_once '../inc/menu_principal.php'; ?>
        <h1>LISTE DES CONTACTS</h1>
        <?php 
while($resultats = mysqli_fetch_array($envoi_requete)){
        ?>
<div>
            <table class="table table-bordered">
                <tr class="active">
                    <th>N°</th>
                    <td>  <?php echo $resultats['id']?>
                    <div class="btn-group" style="float: right;">
                            <button type="button" class="btn btn-warning btn-xs" data-toggle="dropdown">
                                Action
                                <button type="button" class="btn btn-warning btn-xs dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                    <span class="sr-only">Toggle Dropdown</span>
                                </button>
                            </button>
                            <ul class="dropdown-menu" role="menu">
                                <li><a href="modifier_contacts.php?id=<?php echo $resultats["id"]; ?>">Modifier</a></li>
                                <li><a href="supprimer_contacts.php?action=1&id=<?php echo $resultats["id"]; ?>">Supprimer</a></li>
                            </ul>
                        </div>
                    </td>
                </tr>
                <tr>
                    <th>Entreprise</th>
                    <td><?php 
                        //REQUETE SQL
                        $sql_ent = "SELECT raison_sociale FROM entreprises WHERE id=".$resultats["id_entreprise"];
                        $req_ent = mysqli_query($connexion_serveur, $sql_ent);
                        $data_ent = mysqli_fetch_assoc($req_ent);
                        
                        echo $data_ent["raison_sociale"];
                        ?></td>
                </tr>
                <tr>
                    <th>Nom et Prenom</th>
                    <td>  <?php echo $resultats['nom'].''.$resultats['prenom']?></td>
                </tr>
                <tr>
                    <th>Telephone</th>
                    <td>  <?php echo $resultats['telephone']?></td>
                </tr>
                <tr>
                    <th>Email</th>
                    <td>  <?php echo $resultats['email']?></td>
                </tr>
                <tr>
                    <th>Photo</th>
                    <td>  <?php echo $resultats['photo']?></td>
                </tr>
                <tr>
                    <th>Observations</th>
                    <td>  <?php echo $resultats['observations']?></td>
                </tr>
                
            </table>
        </div>
        
     <?php     
        }
        ?>
</html>